package com.hp.controller;

import com.hp.pojo.Jimi;
import com.hp.service.JimiService;
import com.hp.util.PageResult;
import com.hp.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/brand")
public class JimiController {

    @Resource
    private JimiService jimiService;

    @RequestMapping("/findPage")
    @ResponseBody
    public PageResult<Jimi> findPage(int pageNum, int pageSize, @RequestBody Jimi jimi){
        PageResult pageResult = jimiService.fingPage(pageNum, pageSize,jimi);
        return pageResult;
    }

    /*@RequestMapping("/findPage")
    @ResponseBody
    public PageResult<Jimi> findPage(int pageNum, int pageSize){
        PageResult pageResult = jimiService.fingPage(pageNum, pageSize);
        return pageResult;
    }*/

    @RequestMapping("/showIndex")
    public String showIndex(){
        return "index";
    }


    @RequestMapping("/findList")
    @ResponseBody
    public List<Jimi> findList(){
        return jimiService.findList();
    }

    @PostMapping("/add")
    @ResponseBody
    public Result add(@RequestBody Jimi jimi){
        try {
            jimiService.add(jimi);
            return new Result();
        }catch (Exception e){
            e.printStackTrace();
            return new Result(1,"错误");
        }
    }
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody Jimi jimi){
        try {
            jimiService.update(jimi);
            return new Result();
        }catch (Exception e){
            e.printStackTrace();
            return new Result(1,"错误");
        }
    }
    @GetMapping("/findById")
    @ResponseBody
    public Jimi findById(int id){
            Jimi byId = jimiService.findById(id);
            return byId;
    }

    @GetMapping("/delete")
    @ResponseBody
    public Result delete(int id){
        try {
            jimiService.delete(id);
            return new Result();
        }catch (Exception e){
            e.printStackTrace();
            return new Result(1,"错误");
        }
    }
}
